<template>
  <view class="container">
    <button @click="toLogin" v-if="!hasLogin">登录</button>
    <button @click="toRegister" v-if="!hasLogin">注册</button>
    <button @click="toUserCenter" v-if="hasLogin">进入个人中心</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      hasLogin: false
    };
  },
  onLoad() {
    this.checkLogin();
  },
  methods: {
    checkLogin() {
      uni.$u.api.uniIdHasLogin().then(res => {
        this.hasLogin = res.data;
      });
    },
    toLogin() {
      uni.navigateTo({
        url: '/pages/login/login'
      });
    },
    toRegister() {
      uni.navigateTo({
        url: '/pages/register/register'
      });
    },
    toUserCenter() {
      uni.navigateTo({
        url: '/pages/user-center/user-center'
      });
    }
  }
};
</script>